package com.javawork.juc.four;

/**
 * volatile写之前的操作，都禁止重排序到volatile之后
 * volatile 读之后的操作，都禁止重排序到volatile之前
 * volatile 写之后volatile读，禁止重排序
 *
 * @author zhangxiaolu
 * @since 2023-02-11 18:05
 */
public class VolatileUnSortDemo {

    static int i = 0;
    volatile static boolean flag = false;

    public static void write() {
        i = 2;
        flag = true;
    }

    public static void read() {
        if (flag) {
            System.out.println("----i = " + i);
        }
    }

}
